const assert = require('assert');
var MD5 = require('md5')

const PHONE_PATTERN = /(13\d|14[579]|15[^4\D]|17[^49\D]|18\d)\d{8}/g;

/**
 * 电话号码验证
 * @param {string} val 
 */
const isPhone = (val) => {
	return PHONE_PATTERN.test(val);
};

/**
 * 空值验证
 * @param {*} val 
 */
const isNull = (val) => {
	return val === undefined || val === null;
};

/* 
	自定义错误
 */
const throwError = (code, message) => {
	const err = new Error(message);
	err.code = code;
	throw err;
};


const md5 = function(val) {
	const solt = "biluo"
	var passSolt = MD5(MD5(val) + solt);
	return passSolt
}

const upload = require('./upload')


module.exports = {
	assert,
	throwError,
	isPhone,
	isNull,
	md5,
	upload
};
